// subHoliday/holidayDetail/holiday_detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    steps: [],
    id: null, //查看的id
    jsonDetail: null,
    active: null
  },
  // 获取详细接口
  async getHolidayDetail() {
    wx.showLoading({
      title: '加载中',
    })
    try {
      const json = await getApp().$axios("/getLeaveDetailInfo?id=" + this.data.id, "GET")
      wx.hideLoading()
      if (json.status !== 200) {
        wx.showToast({
          title: json.data,
          icon: 'none'
        })
        return
      }
      this.handleData(json.data)
      this.setData({
        jsonDetail: json.data
      })
    } catch (error) {
      wx.showToast({
        title: error.msg,
        icon: 'error'
      })
    }
  },
  // 处理步骤条数据
  handleData(data) {
    if (data.tea_approve_ID && data.counsellor) {
      if (data.tea_status == 0) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '老师审批中',
            desc: '审批中',
            inactiveIcon: 'like-o',
            activeIcon: 'star-o',
          },
          {
            text: '辅导员审批中',
            desc: '等待中',
            inactiveIcon: 'like-o',
            activeIcon: 'plus',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      } else if (data.tea_status == 1) {
        if (data.coun_status == 0) {
          const arr = [{
              text: data.UserInfo.username + '发起',
              desc: '发起成功！',
              inactiveIcon: 'location-o',
              activeIcon: 'success',
            },
            {
              text: '老师审批通过',
              desc: '已同意',
              inactiveIcon: 'certificate',
              activeIcon: 'certificate',
            },
            {
              text: '辅导员审批中',
              desc: '审批中',
              inactiveIcon: 'like-o',
              activeIcon: 'plus',
            }
          ]
          this.setData({
            steps: arr,
            active: 2
          })
        } else if (data.coun_status == 1) {
          const arr = [{
              text: data.UserInfo.username + '发起',
              desc: '发起成功！',
              inactiveIcon: 'location-o',
              activeIcon: 'success',
            },
            {
              text: '老师审批通过',
              desc: '已同意',
              inactiveIcon: 'certificate',
              activeIcon: 'certificate',
            },
            {
              text: '辅导员审批通过',
              desc: '已同意',
              inactiveIcon: 'certificate',
              activeIcon: 'certificate',
            }
          ]
          this.setData({
            steps: arr,
            active: 2
          })
        } else {
          const arr = [{
              text: data.UserInfo.username + '发起',
              desc: '发起成功！',
              inactiveIcon: 'location-o',
              activeIcon: 'success',
            },
            {
              text: '老师审批通过',
              desc: '已同意',
              inactiveIcon: 'certificate',
              activeIcon: 'certificate',
            },
            {
              text: '辅导员审批不通过',
              desc: '已拒绝',
              inactiveIcon: 'cross',
              activeIcon: 'cross',
            }
          ]
          this.setData({
            steps: arr,
            active: 2
          })
        }
      } else if (data.tea_status == 2) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '老师审不通过',
            desc: '已拒绝，流程结束',
            inactiveIcon: 'cross',
            activeIcon: 'cross',
          },
          {
            text: '辅导员审批结束',
            desc: '流程结束',
            inactiveIcon: 'like-o',
            activeIcon: 'plus',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      }
    } else if (data.tea_approve_ID && data.counsellor == null) {
      // 不需要辅导员审批
      if (data.tea_status == 0) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '老师审批中',
            desc: '审批中',
            inactiveIcon: 'like-o',
            activeIcon: 'star-o',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      } else if (data.tea_status == 1) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '老师审批通过',
            desc: '已同意',
            inactiveIcon: 'certificate',
            activeIcon: 'certificate',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      } else {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '老师审批不通过',
            desc: '已拒绝，流程结束',
            inactiveIcon: 'cross',
            activeIcon: 'cross',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      }
    } else if (data.tea_approve_ID == null && data.counsellor) {
      // 不需要老师审批
      if (data.coun_status == 0) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '辅导员审批中',
            desc: '审批中',
            inactiveIcon: 'like-o',
            activeIcon: 'star-o',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      } else if (data.coun_status == 1) {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '辅导员审批通过',
            desc: '已同意，流程结束',
            inactiveIcon: 'certificate',
            activeIcon: 'certificate',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      } else {
        const arr = [{
            text: data.UserInfo.username + '发起',
            desc: '发起成功！',
            inactiveIcon: 'location-o',
            activeIcon: 'success',
          },
          {
            text: '辅导员审批不通过',
            desc: '已拒绝，流程结束',
            inactiveIcon: 'cross',
            activeIcon: 'cross',
          }
        ]
        this.setData({
          steps: arr,
          active: 1
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const id = options.id
    this.setData({
      id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getHolidayDetail()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})